package com.kapo.egroup.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kapo.egroup.common.Result;
import com.kapo.egroup.entity.base.config.Major;
import com.kapo.egroup.entity.base.config.ProjectType;
import com.kapo.egroup.entity.base.config.School;
import com.kapo.egroup.entity.base.lesson.LessonTask;
import com.kapo.egroup.entity.base.project.Project;
import com.kapo.egroup.mapper.MajorMapper;
import com.kapo.egroup.mapper.ProjectTypeMapper;
import com.kapo.egroup.mapper.SchoolMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Title ConfigController
 * @Description TODO
 * @Author 86159
 * @Date 2023-04-01 21:53
 **/
@RestController
@RestControllerAdvice
@RequestMapping("/api/config")
public class ConfigController {
    @Autowired
    SchoolMapper schoolMapper;

    @Autowired
    MajorMapper majorMapper;

    @Autowired
    ProjectTypeMapper projectTypeMapper;

    /**
     * @descriptions 获取项目全局配置学院数据
     * @author 黄家宝
     * @date 2022/8/18 17:28
     * @return com.eintern.common.Result
     */
    @CrossOrigin
    @ResponseBody
    @GetMapping("/school")
    public Result getSchoolConfig() throws Exception{
        QueryWrapper<School> queryWrapper = new QueryWrapper<>();
        List<School> schoolList = schoolMapper.selectList(queryWrapper);
        System.out.println(schoolList);
        return Result.ok(schoolList);
    }

    /**
     * @descriptions 获取项目全局配置专业数据
     * @author 黄家宝
     * @date 2022/8/18 17:28
     * @return com.eintern.common.Result
     */
    @CrossOrigin
    @ResponseBody
    @GetMapping("/major")
    public Result getMajorConfig() throws Exception{
        QueryWrapper<Major> queryWrapper = new QueryWrapper<>();
        List<Major> majorList = majorMapper.selectList(queryWrapper);
        System.out.println(majorList);
        return Result.ok(majorList);
    }

    /**
     * @descriptions 根据学院id获取项目全局配置专业数据
     * @author 黄家宝
     * @date 2022/8/18 17:28
     * @return com.eintern.common.Result
     */
    @CrossOrigin
    @ResponseBody
    @GetMapping("/major/{schoolId}")
    public Result getMajorConfigBySchoolId(@PathVariable Long schoolId) throws Exception{
        QueryWrapper<Major> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("school_id",schoolId);
        List<Major> majorList = majorMapper.selectList(queryWrapper);
        System.out.println(majorList);
        return Result.ok(majorList);
    }

    /**
     * @descriptions 获取项目全局配置学院数据
     * @author 黄家宝
     * @date 2022/8/18 17:28
     * @return com.eintern.common.Result
     */
    @CrossOrigin
    @ResponseBody
    @GetMapping("/projecttype")
    public Result getProjectTypeConfig() throws Exception{
        QueryWrapper<ProjectType> queryWrapper = new QueryWrapper<>();
        List<ProjectType> projectTypeList = projectTypeMapper.selectList(queryWrapper);
        System.out.println(projectTypeList);
        return Result.ok(projectTypeList);
    }
}
